package com.example.ziru.controller;

import com.example.ziru.service.RoomsService;
import com.example.ziru.utils.Result;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/rooms")
@CrossOrigin
public class RoomsController {
    @Autowired
    private RoomsService roomsService;

    @GetMapping("/getAll")
    @ResponseBody
    public Result getAllRooms(){
        //PageHelper.startPage(1,10);
        return new Result("200","成功",roomsService.getAllRooms());
    }

    @RequestMapping("/queryRooms")
    @ResponseBody
    public Object queryRooms(String column,Integer pageIndex,Integer pageSize){
        Result result = roomsService.queryRooms(column,pageIndex,pageSize);
        return result;
    }

    @RequestMapping("/queryRoomsByPriceAsc")
    @ResponseBody
    public Object queryRoomsByPriceAsc(String column,Integer pageIndex,Integer pageSize){
        Result result = roomsService.queryRoomsByPriceAsc(column,pageIndex,pageSize);
        return result;
    }
    @RequestMapping("/queryRoomsByAreaAsc")
    @ResponseBody
    public Object queryRoomsByAreaAsc(String column,Integer pageIndex,Integer pageSize){
        Result result = roomsService.queryRoomsByAreaAsc(column,pageIndex,pageSize);
        return  result;
    }

    @RequestMapping("/queryRoomsById")
    @ResponseBody
    public Object queryRoomsById(Integer id){
        return roomsService.queryRoomsById(id);
    }
    @RequestMapping("/select")
    @ResponseBody
    public Object select(String column,Integer pageIndex,Integer pageSize,String str){
        return roomsService.select(column,pageIndex,pageSize,str);
    }

    @RequestMapping("/queryRoomsByRand")
    @ResponseBody
    public Object queryRoomsByRand(){
        return roomsService.queryRoomsByRand();
    }

    @RequestMapping("/queryTitleByRoomId")
    @ResponseBody
    public Object queryTitleByRoomId(Integer id){
        return roomsService.queryTitleByRoomId(id);
    }
}
